package com.tuling.tulingmall.ordercurr.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.boot.autoconfigure.MybatisProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * MyBatis配置类
 */
@Configuration
@MapperScan({"com.tuling.tulingmall.ordercurr.mapper","com.tuling.tulingmall.ordercurr.dao"})
public class MyBatisConfig {

//    @Autowired
//    private MybatisProperties mybatisProperties;
//
//    @Bean
//    public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource) throws Exception {
//        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
//
//        sqlSessionFactoryBean.setMapperLocations(resolveMapperLocations(mybatisProperties));
//        sqlSessionFactoryBean.setDataSource(new DataSourceProxy(dataSource));
//        return sqlSessionFactoryBean;
//    }
//
//    public Resource[] resolveMapperLocations(MybatisProperties mybatisProperties) {
//        ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
//        List<Resource> resources = new ArrayList<Resource>();
//        if (this.mybatisProperties.getMapperLocations() != null) {
//            for (String mapperLocation : mybatisProperties.getMapperLocations()) {
//                try {
//                    Resource[] mappers = resourceResolver.getResources(mapperLocation);
//                    resources.addAll(Arrays.asList(mappers));
//                } catch (IOException e) {
//                    // ignore
//                }
//            }
//        }
//        return resources.toArray(new Resource[resources.size()]);
//    }



}
